import React, { Component } from 'react'
import Header from '../../components/header/header'
import "./Home.less"
import Cate from './components/cate/cate'
import { connect } from 'react-redux'
import {actions, getInfo, getPre,getGroupon,getCount,getSeckill,getIndexgoods,getHomeN} from "../../store/modules/home"
import { bindActionCreators } from 'redux'
import Groupon from './components/groupon/groupon'
import Countdown from './components/countdown/countdown'
import Seckill from './components/seckill/seckill'
import Indexgoods from './components/indexgoods/indexgoods'

class Home extends Component {
  componentDidMount(){
    let {home:{reqInfo,reqGroupon,reqSeckill,reqCount,reqIndexgoods}} = this.props
    reqInfo();//新人
    reqGroupon();//万人团
    reqSeckill();//秒杀
    // reqCount();//倒计时
    reqIndexgoods();//首页详情
  }

  render() {
    let {info,reqPre,grpupon,count,seckill,indexgoods,n,home:{changeHomeN}} = this.props
    // console.log(this.props);
    return (
      <div>
          <Header text="首页"></Header>
          <div className='con'>
              <Cate info={info} reqPre={reqPre}></Cate>
              <Groupon grpupon={grpupon} reqPre={reqPre}></Groupon>
              <Countdown count={count} reqPre={reqPre}></Countdown>
              <Seckill seckill={seckill} reqPre={reqPre}></Seckill>
              <Indexgoods indexgoods={indexgoods} reqPre={reqPre} n={n} changeHomeN={changeHomeN}></Indexgoods>
          </div>
      </div>
    )
  }
}

const mapStateToProps=(state)=>{
  return {
    info:getInfo(state),
    reqPre:getPre(state),
    grpupon:getGroupon(state),
    count:getCount(state),
    seckill:getSeckill(state),
    indexgoods:getIndexgoods(state),
    n:getHomeN(state)
  }
};
const mapDispatchToProps=(dispatch)=>{
  return{
      home:bindActionCreators(actions,dispatch)
  }
}
export default connect(mapStateToProps, mapDispatchToProps)(Home)